var HOST = $('body').attr('data-host');

$("a[data-show]").click(function () {
    var id = $(this).attr('id');
    var data_show = $(this).attr('data-show');
    if (data_show == 1) {
        $.ajax({
            type: 'POST',
            url: HOST + '/cloud.manage/show',
            data: {'id': id, 'data-show': 1},
            async: false,
            success: function (data) {
                if (data.info == 1) {
                    $("#" + id).text('不显示');
                    $("#" + id).attr('data-show', 2);
                    toastr.success('修改状态成功');
                } else {
                    $("#" + id).text('显示');
                    $("#" + id).attr('data-show', 1);
                    toastr.success('修改状态成功');
                }
            }
        });
    } else {
        $.ajax({
            type: 'POST',
            url: HOST + '/cloud.manage/show',
            data: {'id': id, 'data-show': 2},
            async: false,
            success: function (data) {
                if (data.info == 1) {
                    $("#" + id).text('显示');
                    $("#" + id).attr('data-show', 1);
                    toastr.success('修改状态成功');
                } else {
                    $("#" + id).text('不显示');
                    $("#" + id).attr('data-show', 2);
                    toastr.success('修改状态成功');
                }
            }
        });
    }
});


$("a[data-recommand]").click(function () {
    var id = $(this).attr('class');
    var data_recommand = $(this).attr('data-recommand');

    if(data_recommand == 1) {
        $.ajax({
            type: 'POST',
            url: HOST + '/cloud.manage/recommand',
            data: {'id': id, 'data-recommand': 1},
            async: false,
            success: function (data) {
                if (data.info == 1) {
                    $("." + id).text('不推荐');
                    $("." + id).attr('data-recommand', 2);
                    toastr.success('修改推荐状态成功');
                } else {
                    $("." + id).text('推荐');
                    $("." + id).attr('data-recommand', 1);
                    toastr.success('修改推荐状态成功');
                }
            }
        });
    } else {
        $.ajax({
            type: 'POST',
            url: HOST + '/cloud.manage/recommand',
            data: {'id': id, 'data-recommand': 2},
            async: false,
            success: function (data) {
                if (data.info == 1) {
                    $("." + id).text('推荐');
                    $("." + id).attr('data-recommand', 1);
                    toastr.success('修改推荐状态成功');
                } else {
                    $("." + id).text('不推荐');
                    $("." + id).attr('data-recommand', 2);
                    toastr.success('修改推荐状态成功');

                }
            }
        });
    }
});


$("a[name=del]").click(function () {
    if (confirm('请确定是否删除图片？')) {
        var id = $(this).attr('id');
        $.ajax({
            type: 'POST',
            url: HOST + '/cloud.manage/del',
            data: {'id': id},
            async: false,
            success: function (data) {
                if (data.info == 1) {
                    toastr.success('删除成功');
                } else {
                    toastr.error('发生异常');
                }
            }
        });
        $(this).parents('tr').remove();
    }

});

$("a[name=detail]").click(function () {
    var shop_id = $(this).attr('id');
    window.location.href = HOST + "/cloud.changegoods/index?id=" + shop_id;

    //location.replace(HOST+"/cloud.changegoods/index?id=shop_id");
    // $.ajax({
    //     type:'post',
    //     url:HOST+"/cloud.changegoods/index",
    //     data:{'shop_id':shop_id},
    //     success:function (data) {
    //         if(data.info == 2){
    //             toastr.error('发生异常');
    //             return false;
    //         }
    //
    //     }
    // });

});